﻿/*
 * RendererList
 * 
 * initial implementation : 20.10.2008
 *
 * Copyright (c) Adam Sida, asida@centrum.cz.
 * All rights reserved.
 * 
 * for license see Petra.Gis.License.txt
 */
using System;
using System.Collections;
using System.Collections.Generic;
using Petra.Gis.RenderingServices.PlanarBase.Support;

namespace Petra.Gis.RenderingServices.PlanarBase
{


  /// <summary>
  /// xaml wrapper for renderers
  /// </summary>
  public class RendererList : ChildItemsList<RendererBase>
  {

    private RenderableLegendNodeBase _ownerNode;


    //private IList<RendererBase> _items;




    internal RendererList(RenderableLegendNodeBase parent)
      :base()
    {
      _ownerNode = parent;
      //_items = new List<RendererBase>();
    }




    internal RendererList(RenderableLegendNodeBase parent, IList<RendererBase> storage)
      :base(storage)
    {
      _ownerNode = parent;
    }




    /// <summary>
    /// Adds an item to the end of the item list
    /// </summary>
    /// <param name="item">The item to be added to the end of the list</param>
    public override void Add(RendererBase newChild)
    {
      if (IsReadOnly)
        throw new InvalidOperationException();

      __setParent(_ownerNode, newChild);
      base.Add(newChild);
      newChild.PrepareToRender();
    }




    ///// <summary>
    ///// indicates whether list is readonly.
    ///// </summary>
    //public override bool IsReadOnly
    //{
    //  get { return false; }
    //}




    /// <summary>
    /// Gets or sets the element at the specified index.
    /// </summary>
    /// <param name="index">The zero-based index of the element to get or set.</param>
    /// <returns>The item at the specified index.</returns>
    public virtual RendererBase this[int index]
    {
      get { return base[index]; }
      set 
      {
        if (IsReadOnly)
          throw new InvalidOperationException();

        __setParent(_ownerNode, value);
        base[index] = value;
        value.PrepareToRender();
      }
    }




    /// <summary>
    /// Inserts an item into the list at the specified index.
    /// </summary>
    /// <param name="index">The zero-based index at which item should be inserted.</param>
    /// <param name="item">The item to insert.</param>
    public virtual void Insert(int index, RendererBase item)
    {
      if (IsReadOnly)
        throw new InvalidOperationException();

      __setParent(_ownerNode, item);
      item.PrepareToRender();
      base.Insert(index, item);
    }


  }

}
